# Maintainer: <matheus-catarino@hotmail.com>

_realname=zeal
_builddir=build
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.6.1
pkgrel=4
pkgdesc="Offline documentation browser inspired by Dash (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/zealdocs/${_realname}"
license=("GPL3")
depends=("${MINGW_PACKAGE_PREFIX}-libarchive"
         "${MINGW_PACKAGE_PREFIX}-qt5-base"
         "${MINGW_PACKAGE_PREFIX}-qtwebkit")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-extra-cmake-modules"
             "${MINGW_PACKAGE_PREFIX}-cc")
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/zealdocs/${_realname}/archive/v${pkgver}.tar.gz"
        "https://github.com/zealdocs/zeal/pull/1218.patch")
sha256sums=('095c08f9903071849d5c79878abd48237ce1615f16d324afff1873ab6b5f0026'
            '369fb1b3ed9bcd97ef70fc5b8690d549e5e4042b4c218390ecae2d7acedf8307')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}/1218.patch"
}

build() {
  [[ -d "${srcdir}"/build-${MSYSTEM} ]] && rm -rf ${srcdir}/build-${MSYSTEM}
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G "Ninja" \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DZEAL_PORTABLE_BUILD=OFF \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake.exe --build ./
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  install -Dm755 bin/zeal.exe ${pkgdir}${MINGW_PREFIX}/bin/zeal.exe
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/COPYING ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
